// bzoj1066
// 题意：给定n*m个高度不超过4的柱子，现在有若干蜥蜴初始在一些柱子上，
//       它们每次跳可以跳到曼哈顿距离不超过d的还存在的柱子上，然后当前
//       所在柱子高度减一直到消失。如果跳到边界就算逃离。现在问最多可以
//       逃离多少个蜥蜴。
//
// 题解：想象一个蜥蜴逃离路线就是一个流，然后求最大流就好了。
//
// run: $exec < input
// std: c++03
#include <iostream>
#include <vector>
#include <limits>
#include <queue>
#include <cstdlib>

template <class T>
struct dinic
{
	typedef T value_type;
	typedef int size_type;
	typedef std::vector<size_type>::iterator edge_iter;

	struct edge {
		size_type from, to;
		value_type capacity, flow;
	};

	dinic(size_type num) : size(num)
	{
		graph.resize(num);	//[0, num)
		dist.resize(num);	//[0, num)
	}

	void add_edge(int u, int v, value_type cap = capacity_inf)
	{
		edge tmp;
		tmp.from = u; tmp.to = v; tmp.capacity = cap; tmp.flow = 0;
		edges.push_back(tmp);
		graph[u].push_back(edges.size() - 1);

		tmp.from = v; tmp.to = u; tmp.capacity = 0; tmp.flow = 0;
		edges.push_back(tmp);
		graph[v].push_back(edges.size() - 1);
	}

	bool bfs_label(size_type source, size_type target)
	{
		std::fill(dist.begin(), dist.end(), -1);
		std::queue<size_type> q;
		q.push(source);
		dist[source] = 0;
		while (!q.empty()) {
			size_type now = q.front();
			q.pop();
			for (edge_iter it = graph[now].begin(); it != graph[now].end(); ++it) {
				edge e = edges[*it];
				if (dist[e.to] == -1 && e.capacity > e.flow) {
					q.push(e.to);
					dist[e.to] = dist[now] + 1;
				}
			}
		}
		return dist[target] != -1;
	}

	value_type dfs(size_type v, size_type target, value_type f)
	{
		if (v == target || !f) return f;
		value_type block_flow = 0;
		for (edge_iter it = graph[v].begin(); it != graph[v].end(); ++it) {
			edge & e = edges[*it];
			if (e.capacity > e.flow && dist[e.to] == dist[v] + 1) {
				value_type tmp = dfs(e.to, target,
						std::min(e.capacity - e.flow, f - block_flow));
				block_flow += tmp;
				e.flow += tmp;
				edges[(*it) ^ 1].flow -= tmp;
			}
		}
		if (!block_flow) dist[v] = -1;
		return block_flow;
	}

	value_type max_flow(size_type source, size_type target)
	{
		value_type flow = 0;
		for (int tmp; bfs_label(source, target); )
			while ((tmp = dfs(source, target, capacity_inf))) flow += tmp;
		return flow;
	}

//private:
	value_type static const capacity_inf = 1 << 30;
	size_type size;
	std::vector<int> dist;
	std::vector<edge> edges;
	std::vector<std::vector<size_type> > graph;
};

int const maxn = 21;
int height[maxn][maxn];
int n, m, d, s, t;

int in(int x, int y)
{
	return (x - 1) * m + y;
}

int out(int x, int y)
{
	return n * m + (x - 1) * m + y;
}

void build(int x, int y, dinic<int> & din)
{
	bool target = false;
	for (int i = x - d; i <= x + d; i++)
		for (int j = y - d; j <= y + d; j++) {
			if (i < 1 || i > n || j < 1 || j > m) { target = true; continue; }
			int dis = std::abs(i - x) + std::abs(j - y);
			if (!(dis && dis <= d)) continue;
			din.add_edge(out(x, y), in(i, j));
		}
	if (target)
		din.add_edge(out(x, y), t);
}

int main()
{
	std::cin >> n >> m >> d;
	s = 0; t = n * m * 2 + 1;
	dinic<int> din(t + 2);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char ch;
			std::cin >> ch;
			height[i][j] = ch - '0';
		}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			din.add_edge(in(i, j), out(i, j), height[i][j]);
			build(i, j, din);
		}

	int tot = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char ch;
			std::cin >> ch;
			if (ch == 'L') {
				din.add_edge(s, in(i, j), 1);
				tot++;
			}
		}

	std::cout << tot - din.max_flow(s, t) << '\n';
}

